package cn.shop.utils;

import cn.hutool.http.HttpUtil;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 通过指定的enum值获取enum
 * @author : 李一涵
 * @date : Created in 2021-10-29 17:35
 */
public class EnumUtil {

    /**
     * 通过传入的枚举和其定义的值来获取枚举对象
     *
     * @param enumType 枚举类
     * @param value 枚举里定义的某个值
     * @return 获取到的枚举对象
     *
     */
    public static<T extends Enum<T>> T getEnum(Class<T> enumType, Object value)
            throws InvocationTargetException, IllegalAccessException {
        for (Enum<?> enumConstant : enumType.getEnumConstants()) {
            for (Method method1 : enumConstant.getClass().getDeclaredMethods()) {
                if (method1.getParameterCount() == 0) {
                    if (method1.invoke(enumConstant).equals(value)) {
                        return Enum.valueOf(enumType, enumConstant.name());
                    }
                }
            }

        }
        return null;
    }

    public static void main(String[] args) throws Exception {
        //String BUY_PATH = "d:\\mirserver/Mir200/Envir/QuestDiary/担保交易/商品.txt";
        //File file = new File(BUY_PATH);
        //System.out.println(file.getParentFile());
        //System.out.println(getEnum(Status.class, "正常"));
        //System.out.println(IdWorker.getId());

        ExecutorService e = Executors.newFixedThreadPool(2);
        e.execute(new Test());
        e.execute(new Test());
        e.execute(new Test());
        e.execute(new Test());

    }
}

class Test extends Thread {
    @Override
    public void run() {
        System.out.println(HttpUtil.createPost("http://8.130.26.238/shop-front/api/v1/withdraw")
                .header("shop-token","ae47d65a-f7cf-4e0c-a5a9-6d1ef7d54038")
                .body("{\"amount\":\"4500\",\"id\":\"1556822397775167489\",\"password\":\"11111111\",\"type\":\"1\"}")
                .execute().body());
    }
}
